package cn.edu.nju.ws.sview.rdf;

/**
 * typed literal
 * 
 * @author Gong Saisai
 * 
 */
public class TypedLiteral extends Literal {
	private URIResource datatypeURI = null;

	/**
	 * 
	 * @param lexicalForm
	 *            typed literal lexical form
	 * @param datatypeURI
	 *            typed literal datatype URI
	 */
	TypedLiteral(String lexicalForm, URIResource datatypeURI) {
		super(lexicalForm);
		this.datatypeURI = datatypeURI;
	}

	/**
	 * 
	 * @return literal datatype URI
	 */
	public URIResource getDatatypeURI() {
		return this.datatypeURI;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result =1 ;
		result = prime * result+this.lexicalForm.hashCode();
		result = prime * result
				+ ((datatypeURI == null) ? 0 : datatypeURI.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
	    if(obj instanceof PlainLiteral){
	    	TypedLiteral pliteral = (TypedLiteral)obj;
	    	if(this.lexicalForm.equals(pliteral.getLexicalForm())&&
	    			this.datatypeURI.equals(pliteral.getDatatypeURI()))
                 return true;             
	    }
		return false;
	}
	
	public String toString() {
		return "\"" + this.lexicalForm + "\"" + "^^"
				+ this.datatypeURI.toString();
	}
}